package test.br.com.lh.urabuilder.command
{
	import br.com.lh.urabuilder.command.AddActionCommand;
	import br.com.lh.urabuilder.command.SaveConditionalPropertiesCommand;
	import br.com.lh.urabuilder.domain.xml.ConditionalAction;
	import br.com.lh.urabuilder.domain.xml.Option;
	import br.com.lh.urabuilder.event.AddActionEvent;
	import br.com.lh.urabuilder.event.SaveConditionalPropertiesEvent;
	import br.com.lh.urabuilder.view.ActionComponent;
	
	import flexunit.framework.TestCase;
	import flexunit.framework.TestSuite;
	
	import mx.collections.ArrayCollection;

	public class SaveConditionalPropertiesCommandTest extends TestCase
	{

		public function SaveConditionalPropertiesCommandTest(methodName:String=null)
		{
			super(methodName);
		}

		public static function suite():TestSuite
		{
			var ts:TestSuite=new TestSuite();
			ts.addTest(new SaveConditionalPropertiesCommandTest("shouldCreateArrowsFromTheElementToTheOptionList"));
			return ts;
		}


		public function shouldCreateArrowsFromTheElementToTheOptionList():void
		{
			var conditionalElement:ActionComponent=new ActionComponent();
			conditionalElement.loadComponent("Conditional",0,0,0);
			var playSound1:ActionComponent=new ActionComponent();
			playSound1.loadComponent("PlaySound",0,0,1);
			var playSound2:ActionComponent=new ActionComponent();
			playSound2.loadComponent("PlaySound",0,0,2);
			new AddActionCommand().execute(new AddActionEvent(conditionalElement));
			new AddActionCommand().execute(new AddActionEvent(playSound1));
			new AddActionCommand().execute(new AddActionEvent(playSound2));
			playSound1.buildPoints();
			playSound2.buildPoints();
			conditionalElement.buildPoints();
			var optionList:ArrayCollection=new ArrayCollection();
			var object:Option = new Option();
			object.nextId = 1;
			object.pattern = "1";
			optionList.addItem(object);
			object = new Option();
			object.nextId = 2;
			object.pattern = "1";
			optionList.addItem(object);  
			var saveConditionalPropertiesEvent:SaveConditionalPropertiesEvent=new SaveConditionalPropertiesEvent(conditionalElement, optionList);
			new SaveConditionalPropertiesCommand().execute(saveConditionalPropertiesEvent);
			assertTrue(conditionalElement.outArrows.length ==2);
			assertTrue(conditionalElement.outArrows.getItemAt(0).endComponent == playSound1);
			assertTrue(conditionalElement.outArrows.getItemAt(1).endComponent == playSound2);
		}

	}
}
